<template>
    <!-- 添加或修改项目基础信息管理对话框 -->
    <div>
        <!--    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleChose">商品选择</el-button>-->
        <el-table border v-loading="loading" :default-sort="{ prop: 'goodsCode', order: 'descending' }" ref="dragTable"
            :data="columns" row-key="id">
            <el-table-column label="序号" type="index" width="50" align="center">
                <template slot-scope="scope">
                    <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column sortable label="工程名称" align="center" prop="gongchengName" show-overflow-tooltip />
            <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
            <el-table-column  label="产品名称" align="center" prop="goodsName"  show-overflow-tooltip/>
            <!--<el-table-column label="商品品牌" align="center" prop="brand"/>-->
            <el-table-column  label="产品型号" align="center" prop="model" />
            <el-table-column  label="产品单位" align="center" prop="unit" />
            <el-table-column sortable label="产品状态" align="center" prop="status">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.goods_status" :value="scope.row.status" />
                    </template>
                </el-table-column>
            <!--<el-table-column label="含税单价" align="center" prop="costPriceTax"/>-->
            <!--      <el-table-column label="采购数量" align="center" prop="count"/>-->
            <!--      <el-table-column label="库存数量" align="center" prop="remainderCount"/>-->
            <el-table-column label="订单单价" align="center" prop="goodsUnitPrice" />
            <el-table-column label="订单数量" align="center" prop="orderCount" />
            <el-table-column label="不含税总价" align="center" prop="goodsTotalPrice" />
            <el-table-column label="订单总价" align="center" prop="goodsTaxTotalPrice" />
            <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
            <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-popconfirm :title="`确认删除 `+scope.row.goodsName+` 数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>-->
        </el-table>
    </div>
</template>

<script>

import { addAction, deleteAction, getAction, getById, updateAction } from '@/api/manage'
// import GoodsOrderinChose from "./GoodsOrderinChose";
import { updateGoodsSale } from '@/api/develop/goodsProject'

export default {
    name: "GoodsSaleListForPrjForm",
    dicts: ['goods_customer', 'company', 'yes_no', 'goods_status'],
    components: {
        // GoodsOrderinChose
    },
    props: {
        projectId: {
            type: [String, Number],
            required: true,
            default: ''
        },
        type: {
            type: String,
            required: true,
            default: ''
        },
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            activeName: "first",
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 表单参数
            form: {},
            proId: "",
            columns: [],
            total: 0,
            // 表单校验
            rules: {
                name: [
                    { required: true, message: "项目名称不能为空", trigger: "blur" }
                ],
                master: [
                    { required: true, message: "项目负责人不能为空", trigger: "blur" }
                ],
                customId: [
                    { required: true, message: "客户信息不能为空", trigger: "blur" }
                ],
            },
            queryParams: {
                pageNum: 1,
                pageSize: 1000,
                id: null,
                name: null,
                taxNo: null,
                addr: null,
                tel: null,
                bankName: null,
                bankNo: null,
                info: null,
                //status: "0",
                delFlag: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null,
                orderByColumn: "createTime",
                isAsc: "desc"
            },
            url: {
                list: '/goodsSale/goodsSale/listSaleProject',
                listBatch: '/goodsSale/goodsSale/listBatchSale/',
                getById: '/projectBaseInfo/projectBaseInfo/',
                add: '/projectBaseInfo/projectBaseInfo/add',
                edit: '/projectBaseInfo/projectBaseInfo/edit',
                remove: '/goodsSale/goodsSale/deleteProject/',
            },
        };
    },
    watch: {
        'projectId': {
            handler(newVal, oldVal) {
                if (newVal) {
                    this.queryParams.projectId = newVal;
                    this.queryParams.type = this.type;
                    this.getList();
                }
            },
            deep: true,
            immediate: true
        },
        /*'type': {
            handler(newVal, oldVal) {
                this.queryParams.projectId = this.projectId;
                this.queryParams.type = newVal;
                this.getList();
            },
            deep: true,
            immediate: true
        }*/
    },
    created() {

    },
    methods: {
        /*handleChangeMoney(row) {
            let that = this;
            let handleReckonMoney = (row) => {
                let row_money = 0;
                row_money = that.functionNumberMul(Number(row.goodsUnitPrice), Number(row.goodsCount))
                that.$set(row, 'goodsTotalPrice', row_money);
            };
            handleReckonMoney(row);
        },*/
        /*functionNumberMul(arg1, arg2) {
            var m = 0;
            var s1 = arg1.toString();
            var s2 = arg2.toString();
            try {
                m += s1.split(".")[1].length;
            } catch (e) {
            }
            try {
                m += s2.split(".")[1].length;
            } catch (e) {
            }
            return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
        },*/
        /*handleChose() {
            this.$refs.formChose.chose(this.proId);
        },*/
        getList() {
            this.loading = true;
            /*getById(this.url.listBatch, this.ids).then(response => {
              this.columns = response.rows;
              this.total = response.total;
              this.loading = false;
            });*/
            // this.queryParams.projectId = this.proId
            getAction(this.url.list, this.queryParams).then(response => {
                this.columns = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        handleDelete(row) {
            const ids = row.id || this.ids;
            deleteAction(this.url.remove, ids).then(response => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },
        handleUpdateDetail(row) {
            this.reset();
            const id = row.id || this.ids;
            getById(this.url.getById, id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "完善项目信息";
            });
        },
        updateAuditMoney(value) {
            this.$set(this.form, "auditMoney", value);
        },
        selectCustomerForPrj(value) {
            let that = this;
            that.$nextTick(() => {
                let arr = that.$refs.myselectCustomerForPrj;
                for (let i = 0; i < arr.length; i++) {
                    if (arr[i].currentValue == value) {
                        that.form.customName = arr[i].label;
                    }
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                delFlag: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null,
                name: null,
                master: null,
                customId: null,
                customName: null,
                companyName: null,
                contractDate: null,
                contractMoney: null,
                auditMoney: null,
                checkDate: null,
                checkState: null,
                fundCallback: null,
                infomation: null
            };
            this.resetForm("form");
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加项目基础信息管理";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            this.proId = id;
            getById(this.url.getById, id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改订单基础信息管理";
                this.getList();
            });
        },
        /** 提交按钮 */
        submitForm() {
            let that = this;
            that.$refs["form"].validate(valid => {
                if (valid) {
                    /*const goodsSaleForm = that.form;
                    const goodsOrderIn = Object.assign({}, goodsSaleForm);
                    goodsOrderIn.columns = that.columns;
                    goodsOrderIn.form = goodsSaleForm;
                    updateGoodsSale(goodsOrderIn).then(res => {
                      that.$modal.msgSuccess(res.msg);
                      if (res.code === 200) {
                        that.$modal.msgSuccess("修改完成！");
                        that.open = false;
                        that.$emit('ok');
                      }
                    });*/
                    if (this.form.id != null) {
                        updateAction(this.url.edit, this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.$emit('ok');
                        });
                    } else {
                        addAction(this.url.add, this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.$emit('ok');
                        });
                    }
                }
            });
        },
    }
};
</script>
